//
//  WONoteView.m
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-16.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "WONewNoteViewController.h"
#import "WOHistoryEntry.h"

@implementation WONewNoteViewController
@synthesize textView;
@synthesize backgroundField;
@synthesize delegate;
@synthesize text;

#pragma mark Initialization Methods

- (id) init
{
	return [super initWithNibName:@"NoteView" bundle:[NSBundle mainBundle]];
}

- (void) viewWillAppear:(BOOL)animated
{
	UILabel *titleView = [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 30.0f)] autorelease];
	[titleView setBackgroundColor:[UIColor clearColor]];
	[titleView setTextColor:[UIColor whiteColor]];
	[titleView setTextAlignment:UITextAlignmentCenter];
	[titleView setText:self.title];
	self.navigationItem.titleView = titleView;
	
	[textView becomeFirstResponder];
	self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Klar" 
												   style:UIBarButtonItemStyleDone 
												  target:self 
												  action:@selector(postButtonClicked:)] autorelease];
	if (self.text)
	{
		textView.text = self.text;
		[self textViewDidChange:textView];
	}
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark -

#pragma mark Other Methods

- (void) postButtonClicked:(id)sender
{
	if ([delegate noteView:self shouldReturnWithText:textView.text])
		[self.navigationController popViewControllerAnimated:YES];
}

- (void)textViewDidChange:(UITextView *)aTextView
{
	self.navigationItem.rightBarButtonItem.enabled = ![aTextView.text isEqualToString:@""]; 
}

#pragma mark -

@end
